
import axios from "axios";
import { BASE_URL } from './ApiCons'

// http://localhost:7529/admin/orderList


export type Order = {
    id: number
    createTime: Date
    bookName: string
    accepter: string
    address: string
    num: number
    logistics: string
    signed: number
    price: number
}

export type User = {

    userName: string

    shippingAddress: string

    money: number

    role: string

    headPortrait: string

    regTime: Date

    phoneNumber: string

    realName: string

    status: string
}

export type Book = {
    id:number
    price:number
    info:string
    pic:string
    className:string
    status:number
    bookName:string
}

export function getOrderList(start: number, offset: number): Promise<any> {
    return axios.get(
        BASE_URL + `/admin/orderList?start=${start}&offset=${offset}`
    )
}
export function shiped(id: any) {
    return axios.post(
        BASE_URL + '/admin/shiped',
        {
            id
        }
    )
}

export function getCount() {
    return axios.get(
        BASE_URL + '/admin/count'
    )
}

export function cancleApi(id: number, userName: string, price: string) {
    return axios.post(
        BASE_URL + '/admin/cancel',
        {
            id,
            userName,
            price
        }
    )
}

export class signedType {
    public static NOT_SHIPPED = 0
    public static _SHIPPED = 1;
    public static SINGED = 2;
    public static CANCEL = 3;
}
export function getListByType(type: any) {
    return axios.get(
        BASE_URL + `/admin/signedType?type=${type}`
    )
}

export function getUserList (start:number,offset:number) {
    return axios.get(
        BASE_URL + `/admin/getUserList?start=${start}&offset=${offset}`
    )
}
export function getUserCount ( ) {
    return axios.get(
        BASE_URL + '/admin/userCount'
    )
}

export function changeStatus (userName:any) {
    return axios.post(
        BASE_URL + '/admin/changeStatus',
        {
            userName
        }
    )
}
export  function findUserByName (userName:string) {
    return axios.get(
        BASE_URL + `/admin/findUserById?userName=${userName}`
    )
}

export function confirmMoneyApi (data:any) {
    return axios.post(
        BASE_URL + '/admin/confirmMoney',
        data
    )
}

export function getBookListApi (start:number,offset:number) {
    return axios.get(
        BASE_URL + `/admin/getBookList?start=${start}&offset=${offset}`
    )
}

export const getBookCount = () => {
    return axios.get(
        BASE_URL + '/admin/bookCount'
    )
}

export function getBook (id:any) {
    return axios.get(
        BASE_URL + `/admin/getBook?id=${id}`
    )
}


export const updataBook = (id:number,bookName:string,infor:string,price:number,classId:number) =>{
    return axios.post(
        BASE_URL + '/admin/update',
        {
            id,
            bookName,
            infor,
            price,
            classId
        }
    )
}

export const soldOutApi = (id:any) => {
   return  axios.post(
        BASE_URL + '/admin/soldOut',
        {
            id
        }
    )
}
export function searchApi (data:any) {
    return axios.post(
        BASE_URL + '/admin/search',
        data
    )
}